﻿using System.ComponentModel;
using System.Xml.Serialization;

namespace PanoramaTestApp.Model
{
    public class GlobalSettings : INotifyPropertyChanged
    {
        private static readonly GlobalSettings _default = new GlobalSettings();

        public GlobalSettings()
        {
            ServerAddress = LocalAddress;
            ServerHttpAddress = LocalHttpAddress;
            UseNameFilter = true;
        }

        public static GlobalSettings Default
        {
            get { return _default; }
        }

        internal string LocalAddress = "http://192.168.0.100/PcInfoWebSite/PcInfoService.svc/basic";
        internal string InternetAddress = "http://quantology.dyndns.org/PcInfoWebSite/PcInfoService.svc/basic";

        internal string LocalHttpAddress = "http://192.168.0.100";
        internal string InternetHttpAddress = "http://quantology.dyndns.org";

        private string _serverAddress;

        [XmlElement]
        public string ServerAddress
        {
            get { return _serverAddress; }
            set
            {
                _serverAddress = value;
                OnPropertyChanged(new PropertyChangedEventArgs("ServerAddress"));
            }
        }

        private string _serverHttpAddress;

        

        [XmlElement]
        public string ServerHttpAddress
        {
            get { return _serverHttpAddress; }
            set
            {
                _serverHttpAddress = value;
                OnPropertyChanged(new PropertyChangedEventArgs("ServerHttpAddress"));
            }
        }

        private bool _useNameFilter;

         [XmlElement]
        public bool UseNameFilter
        {
            get { return _useNameFilter; }
            set
            {
                _useNameFilter = value;
                OnPropertyChanged(new PropertyChangedEventArgs("UseNameFilter"));
            }
        }

        private bool _useDateFilter;

         [XmlElement]
        public bool UseDateFilter
        {
            get { return _useDateFilter; }
            set
            {
                _useDateFilter = value;
                OnPropertyChanged(new PropertyChangedEventArgs("UseDateFilter"));
            }
        }

        public void Restore(GlobalSettings readFromXml)
        {
            if (readFromXml != null)
            {
                this.ServerAddress = readFromXml.ServerAddress;
                this.ServerHttpAddress = readFromXml.ServerHttpAddress;
                this.UseNameFilter = readFromXml.UseNameFilter;
                this.UseDateFilter = readFromXml.UseDateFilter;
            }
        }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, e);
        }

        #endregion
    }
}
